/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.dwh.trigger;

/**
 *
 * @author Jose Carlos Palma
 * @version v1.0
 */
public class Configure {
    
    private Configure(){
    }

    public static String getString(String key, String def){
        String val = System.getProperty(key).trim();
        return ( val == null || val.isEmpty() ? def : val);
    }

    public static String getString(String key){
        return getString(key, "");
    }

    public static int getInt(String key, int def){
        String val = System.getProperty(key).trim();
        return ( val == null || val.isEmpty() ? def : Integer.parseInt(val) );
    }

    public static int getInt(String key){
        return getInt(key, -1);
    }
    
    public static String[] getSDPInfo(String ip){
        
        String[] retVal = {"", "", ip};
        
        
        //Recorre todas la keys
        for(String key: System.getProperties().stringPropertyNames()){
            //Verifica si el valor de key es igual a la IP
            if( !key.trim().startsWith("sdp") ) continue;
            System.out.println(key);
            if( System.getProperty(key).trim().equals(ip) ){
                String sdp = key.split("\\.")[0];
                retVal[0] = System.getProperty(sdp + ".sdp" );
                retVal[1] = System.getProperty(sdp + ".slu" );
                retVal[2] = System.getProperty(sdp + ".ip" );
                return retVal;
            }
        }
        return retVal;
    }

}
